package com.honghea.rxhttp;

import com.honghea.rxhttp.BuildConfig;
import com.honghea.rxhttp.factory.IOkHttpClientFactory;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;

public class DefaultClientFactory implements IOkHttpClientFactory {

    @Override
    public OkHttpClient provide() {
        OkHttpClient.Builder builder = new OkHttpClient.Builder()
                .connectTimeout(30, TimeUnit.SECONDS)
                .readTimeout(30,TimeUnit.SECONDS)
                .writeTimeout(30,TimeUnit.SECONDS);
        if (BuildConfig.DEBUG) {
            HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
            interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
            builder.addInterceptor(interceptor);
        }
        builder.addInterceptor(new HttpLoggingInterceptor());
        return builder.build();
    }

}
